package com.learn.hd.select;

import java.util.Arrays;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description 选择排序----简单选择排序
 * @date 2019/7/15
 */
public class SimpleSelectSort {

    public static void main(String[] args) {

        int[] array = new int[]{ 4, 6, 1, 9, 12, 45, 19, 100, 7};

        for (int i = 0; i < array.length ; i++) {

            int k = i;
            for (int j = i+1; j < array.length ; j++) {

                if (array[k] < array[j]) {
                    k = j;
                }
            }
            swap(array, i, k);
        }

        System.out.println(Arrays.toString(array));

    }

    private static void swap(int[] array, int i, int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}
